package ospedale.lettura;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;

import ospedale.IFileInput;
import ospedale.Paziente;

public class LetturaFormatoA implements IFileInput{

	@Override
	public ArrayList<Paziente> getFile() {
		
		String PATHNAME="data/file.txt";
		File file=new File(PATHNAME);
		ArrayList<Paziente> list = new ArrayList<Paziente>();
		String[] word = new String[5];		
		try {
			BufferedReader bReader=new BufferedReader(new FileReader(file));
			String line=bReader.readLine();
			while(line!=null){
				for (int i = 0; i < 5; i++) {
					
					StringTokenizer token = new StringTokenizer(line);
					token.nextToken(":");
					word[i] =  new String();
					word[i] = token.nextToken();
					line=bReader.readLine();
				
				}
				list.add(new Paziente(word[0], word[1], word[2], word[3], word[4]));
				
			}
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

}
